package com.huadi.firematerialident.service;

import com.huadi.firematerialident.dao.AppraisalDaoImpl;
import com.huadi.firematerialident.po.Application;
import com.huadi.firematerialident.po.Appraisal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;


import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AppraisalServiceImpl implements AppraisalService{

    @Autowired
    AppraisalDaoImpl appraisalDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    IdentifierServiceImpl identifierService;

    @Override
    public int addAppraisal(Appraisal appraisal) {
        return appraisalDao.addAppraisal(appraisal);
    }

    @Override
    public int updateAppraisal(Appraisal appraisal) {
        return appraisalDao.updateAppraisal(appraisal);
    }

    @Override
    public int deleteAppraisalByID(String appraisalID) {
        return appraisalDao.deleteAppraisalByID(appraisalID);
    }

    @Override
    public List<Map<String,Object>> selectAppraisalByID(String appraisalID) {
        return appraisalDao.selectAppraisalByID(appraisalID);
    }

    @Override
    public List<Map<String,Object>> selectAppraisalByID1(String AppID){
        return appraisalDao.selectAppraisalByID1(AppID);
    }

    @Override
    public List<Map<String,Object>> getAllAppraisal() {
        return appraisalDao.getAllAppraisal();
    }

    @Override
    public List<Map<String, Object>> getMyAppraisal() {
        String sql="select * from appraisal where IdentID=?";
        return jdbcTemplate.queryForList(sql,identifierService.getIdentID());
    }

    @Override
    public Appraisal selectAppraisalByID_class(String id){
        List<Map<String ,Object>> list = appraisalDao.selectAppraisalByID(id);
        Appraisal appraisal = new Appraisal();
        appraisal.setAppID((String) list.get(0).get("ApsID"));
        appraisal.setAppID((String) list.get(0).get("AppID"));
        appraisal.setIdentID((String) list.get(0).get("IdentID"));
        appraisal.setApsTime((LocalDateTime) list.get(0).get("ApsTime"));
        appraisal.setApsConclusion((String) list.get(0).get("ApsConclusion"));
        appraisal.setArchivingStatus((String) list.get(0).get("ArchivingStatus"));
        appraisal.setLogicalAddDel((boolean) list.get(0).get("LogicalAddDel"));
        appraisal.setLastModification((LocalDateTime) list.get(0).get("LastModification"));
        return appraisal;
    }
}
